using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace CXDB
{
	/// <summary>
	/// Strongly-typed collection for the CxCompanyBase class.
	/// </summary>
    [Serializable]
	public partial class CxCompanyBaseCollection : ActiveList<CxCompanyBase, CxCompanyBaseCollection>
	{	   
		public CxCompanyBaseCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>CxCompanyBaseCollection</returns>
		public CxCompanyBaseCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                CxCompanyBase o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the CX_CompanyBase table.
	/// </summary>
	[Serializable]
	public partial class CxCompanyBase : ActiveRecord<CxCompanyBase>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public CxCompanyBase()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public CxCompanyBase(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public CxCompanyBase(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public CxCompanyBase(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CX_CompanyBase", TableType.Table, DataService.GetInstance("CXDB"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarCompanyID = new TableSchema.TableColumn(schema);
				colvarCompanyID.ColumnName = "CompanyID";
				colvarCompanyID.DataType = DbType.AnsiStringFixedLength;
				colvarCompanyID.MaxLength = 100;
				colvarCompanyID.AutoIncrement = false;
				colvarCompanyID.IsNullable = false;
				colvarCompanyID.IsPrimaryKey = true;
				colvarCompanyID.IsForeignKey = false;
				colvarCompanyID.IsReadOnly = false;
				colvarCompanyID.DefaultSetting = @"";
				colvarCompanyID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCompanyID);
				
				TableSchema.TableColumn colvarCompanyName = new TableSchema.TableColumn(schema);
				colvarCompanyName.ColumnName = "CompanyName";
				colvarCompanyName.DataType = DbType.String;
				colvarCompanyName.MaxLength = 100;
				colvarCompanyName.AutoIncrement = false;
				colvarCompanyName.IsNullable = true;
				colvarCompanyName.IsPrimaryKey = false;
				colvarCompanyName.IsForeignKey = false;
				colvarCompanyName.IsReadOnly = false;
				colvarCompanyName.DefaultSetting = @"";
				colvarCompanyName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCompanyName);
				
				TableSchema.TableColumn colvarCompanyAddress = new TableSchema.TableColumn(schema);
				colvarCompanyAddress.ColumnName = "CompanyAddress";
				colvarCompanyAddress.DataType = DbType.String;
				colvarCompanyAddress.MaxLength = 250;
				colvarCompanyAddress.AutoIncrement = false;
				colvarCompanyAddress.IsNullable = true;
				colvarCompanyAddress.IsPrimaryKey = false;
				colvarCompanyAddress.IsForeignKey = false;
				colvarCompanyAddress.IsReadOnly = false;
				colvarCompanyAddress.DefaultSetting = @"";
				colvarCompanyAddress.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCompanyAddress);
				
				TableSchema.TableColumn colvarTradeID = new TableSchema.TableColumn(schema);
				colvarTradeID.ColumnName = "TradeID";
				colvarTradeID.DataType = DbType.Int32;
				colvarTradeID.MaxLength = 0;
				colvarTradeID.AutoIncrement = false;
				colvarTradeID.IsNullable = true;
				colvarTradeID.IsPrimaryKey = false;
				colvarTradeID.IsForeignKey = false;
				colvarTradeID.IsReadOnly = false;
				colvarTradeID.DefaultSetting = @"";
				colvarTradeID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTradeID);
				
				TableSchema.TableColumn colvarElectricID = new TableSchema.TableColumn(schema);
				colvarElectricID.ColumnName = "ElectricID";
				colvarElectricID.DataType = DbType.Int32;
				colvarElectricID.MaxLength = 0;
				colvarElectricID.AutoIncrement = false;
				colvarElectricID.IsNullable = true;
				colvarElectricID.IsPrimaryKey = false;
				colvarElectricID.IsForeignKey = false;
				colvarElectricID.IsReadOnly = false;
				colvarElectricID.DefaultSetting = @"";
				colvarElectricID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarElectricID);
				
				TableSchema.TableColumn colvarPersonCardID = new TableSchema.TableColumn(schema);
				colvarPersonCardID.ColumnName = "PersonCardID";
				colvarPersonCardID.DataType = DbType.String;
				colvarPersonCardID.MaxLength = 50;
				colvarPersonCardID.AutoIncrement = false;
				colvarPersonCardID.IsNullable = true;
				colvarPersonCardID.IsPrimaryKey = false;
				colvarPersonCardID.IsForeignKey = false;
				colvarPersonCardID.IsReadOnly = false;
				colvarPersonCardID.DefaultSetting = @"";
				colvarPersonCardID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPersonCardID);
				
				TableSchema.TableColumn colvarDepID = new TableSchema.TableColumn(schema);
				colvarDepID.ColumnName = "DepID";
				colvarDepID.DataType = DbType.Int32;
				colvarDepID.MaxLength = 0;
				colvarDepID.AutoIncrement = false;
				colvarDepID.IsNullable = true;
				colvarDepID.IsPrimaryKey = false;
				colvarDepID.IsForeignKey = false;
				colvarDepID.IsReadOnly = false;
				colvarDepID.DefaultSetting = @"";
				colvarDepID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDepID);
				
				TableSchema.TableColumn colvarScores = new TableSchema.TableColumn(schema);
				colvarScores.ColumnName = "Scores";
				colvarScores.DataType = DbType.Int32;
				colvarScores.MaxLength = 0;
				colvarScores.AutoIncrement = false;
				colvarScores.IsNullable = true;
				colvarScores.IsPrimaryKey = false;
				colvarScores.IsForeignKey = false;
				colvarScores.IsReadOnly = false;
				colvarScores.DefaultSetting = @"";
				colvarScores.ForeignKeyTableName = "";
				schema.Columns.Add(colvarScores);
				
				TableSchema.TableColumn colvarCredit = new TableSchema.TableColumn(schema);
				colvarCredit.ColumnName = "Credit";
				colvarCredit.DataType = DbType.String;
				colvarCredit.MaxLength = 50;
				colvarCredit.AutoIncrement = false;
				colvarCredit.IsNullable = true;
				colvarCredit.IsPrimaryKey = false;
				colvarCredit.IsForeignKey = false;
				colvarCredit.IsReadOnly = false;
				colvarCredit.DefaultSetting = @"";
				colvarCredit.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCredit);
				
				TableSchema.TableColumn colvarStatus = new TableSchema.TableColumn(schema);
				colvarStatus.ColumnName = "Status";
				colvarStatus.DataType = DbType.String;
				colvarStatus.MaxLength = 50;
				colvarStatus.AutoIncrement = false;
				colvarStatus.IsNullable = true;
				colvarStatus.IsPrimaryKey = false;
				colvarStatus.IsForeignKey = false;
				colvarStatus.IsReadOnly = false;
				colvarStatus.DefaultSetting = @"";
				colvarStatus.ForeignKeyTableName = "";
				schema.Columns.Add(colvarStatus);
				
				TableSchema.TableColumn colvarEnteringID = new TableSchema.TableColumn(schema);
				colvarEnteringID.ColumnName = "EnteringID";
				colvarEnteringID.DataType = DbType.Int32;
				colvarEnteringID.MaxLength = 0;
				colvarEnteringID.AutoIncrement = false;
				colvarEnteringID.IsNullable = true;
				colvarEnteringID.IsPrimaryKey = false;
				colvarEnteringID.IsForeignKey = false;
				colvarEnteringID.IsReadOnly = false;
				colvarEnteringID.DefaultSetting = @"";
				colvarEnteringID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEnteringID);
				
				TableSchema.TableColumn colvarVerifierID = new TableSchema.TableColumn(schema);
				colvarVerifierID.ColumnName = "VerifierID";
				colvarVerifierID.DataType = DbType.Int32;
				colvarVerifierID.MaxLength = 0;
				colvarVerifierID.AutoIncrement = false;
				colvarVerifierID.IsNullable = true;
				colvarVerifierID.IsPrimaryKey = false;
				colvarVerifierID.IsForeignKey = false;
				colvarVerifierID.IsReadOnly = false;
				colvarVerifierID.DefaultSetting = @"";
				colvarVerifierID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarVerifierID);
				
				TableSchema.TableColumn colvarInTime = new TableSchema.TableColumn(schema);
				colvarInTime.ColumnName = "inTime";
				colvarInTime.DataType = DbType.DateTime;
				colvarInTime.MaxLength = 0;
				colvarInTime.AutoIncrement = false;
				colvarInTime.IsNullable = true;
				colvarInTime.IsPrimaryKey = false;
				colvarInTime.IsForeignKey = false;
				colvarInTime.IsReadOnly = false;
				
						colvarInTime.DefaultSetting = @"(getdate())";
				colvarInTime.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInTime);
				
				TableSchema.TableColumn colvarGuid = new TableSchema.TableColumn(schema);
				colvarGuid.ColumnName = "Guid";
				colvarGuid.DataType = DbType.Guid;
				colvarGuid.MaxLength = 0;
				colvarGuid.AutoIncrement = false;
				colvarGuid.IsNullable = true;
				colvarGuid.IsPrimaryKey = false;
				colvarGuid.IsForeignKey = false;
				colvarGuid.IsReadOnly = false;
				
						colvarGuid.DefaultSetting = @"(newid())";
				colvarGuid.ForeignKeyTableName = "";
				schema.Columns.Add(colvarGuid);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["CXDB"].AddSchema("CX_CompanyBase",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("CompanyID")]
		[Bindable(true)]
		public string CompanyID 
		{
			get { return GetColumnValue<string>(Columns.CompanyID); }
			set { SetColumnValue(Columns.CompanyID, value); }
		}
		  
		[XmlAttribute("CompanyName")]
		[Bindable(true)]
		public string CompanyName 
		{
			get { return GetColumnValue<string>(Columns.CompanyName); }
			set { SetColumnValue(Columns.CompanyName, value); }
		}
		  
		[XmlAttribute("CompanyAddress")]
		[Bindable(true)]
		public string CompanyAddress 
		{
			get { return GetColumnValue<string>(Columns.CompanyAddress); }
			set { SetColumnValue(Columns.CompanyAddress, value); }
		}
		  
		[XmlAttribute("TradeID")]
		[Bindable(true)]
		public int? TradeID 
		{
			get { return GetColumnValue<int?>(Columns.TradeID); }
			set { SetColumnValue(Columns.TradeID, value); }
		}
		  
		[XmlAttribute("ElectricID")]
		[Bindable(true)]
		public int? ElectricID 
		{
			get { return GetColumnValue<int?>(Columns.ElectricID); }
			set { SetColumnValue(Columns.ElectricID, value); }
		}
		  
		[XmlAttribute("PersonCardID")]
		[Bindable(true)]
		public string PersonCardID 
		{
			get { return GetColumnValue<string>(Columns.PersonCardID); }
			set { SetColumnValue(Columns.PersonCardID, value); }
		}
		  
		[XmlAttribute("DepID")]
		[Bindable(true)]
		public int? DepID 
		{
			get { return GetColumnValue<int?>(Columns.DepID); }
			set { SetColumnValue(Columns.DepID, value); }
		}
		  
		[XmlAttribute("Scores")]
		[Bindable(true)]
		public int? Scores 
		{
			get { return GetColumnValue<int?>(Columns.Scores); }
			set { SetColumnValue(Columns.Scores, value); }
		}
		  
		[XmlAttribute("Credit")]
		[Bindable(true)]
		public string Credit 
		{
			get { return GetColumnValue<string>(Columns.Credit); }
			set { SetColumnValue(Columns.Credit, value); }
		}
		  
		[XmlAttribute("Status")]
		[Bindable(true)]
		public string Status 
		{
			get { return GetColumnValue<string>(Columns.Status); }
			set { SetColumnValue(Columns.Status, value); }
		}
		  
		[XmlAttribute("EnteringID")]
		[Bindable(true)]
		public int? EnteringID 
		{
			get { return GetColumnValue<int?>(Columns.EnteringID); }
			set { SetColumnValue(Columns.EnteringID, value); }
		}
		  
		[XmlAttribute("VerifierID")]
		[Bindable(true)]
		public int? VerifierID 
		{
			get { return GetColumnValue<int?>(Columns.VerifierID); }
			set { SetColumnValue(Columns.VerifierID, value); }
		}
		  
		[XmlAttribute("InTime")]
		[Bindable(true)]
		public DateTime? InTime 
		{
			get { return GetColumnValue<DateTime?>(Columns.InTime); }
			set { SetColumnValue(Columns.InTime, value); }
		}
		  
		[XmlAttribute("Guid")]
		[Bindable(true)]
		public Guid? Guid 
		{
			get { return GetColumnValue<Guid?>(Columns.Guid); }
			set { SetColumnValue(Columns.Guid, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varCompanyID,string varCompanyName,string varCompanyAddress,int? varTradeID,int? varElectricID,string varPersonCardID,int? varDepID,int? varScores,string varCredit,string varStatus,int? varEnteringID,int? varVerifierID,DateTime? varInTime,Guid? varGuid)
		{
			CxCompanyBase item = new CxCompanyBase();
			
			item.CompanyID = varCompanyID;
			
			item.CompanyName = varCompanyName;
			
			item.CompanyAddress = varCompanyAddress;
			
			item.TradeID = varTradeID;
			
			item.ElectricID = varElectricID;
			
			item.PersonCardID = varPersonCardID;
			
			item.DepID = varDepID;
			
			item.Scores = varScores;
			
			item.Credit = varCredit;
			
			item.Status = varStatus;
			
			item.EnteringID = varEnteringID;
			
			item.VerifierID = varVerifierID;
			
			item.InTime = varInTime;
			
			item.Guid = varGuid;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varCompanyID,string varCompanyName,string varCompanyAddress,int? varTradeID,int? varElectricID,string varPersonCardID,int? varDepID,int? varScores,string varCredit,string varStatus,int? varEnteringID,int? varVerifierID,DateTime? varInTime,Guid? varGuid)
		{
			CxCompanyBase item = new CxCompanyBase();
			
				item.CompanyID = varCompanyID;
			
				item.CompanyName = varCompanyName;
			
				item.CompanyAddress = varCompanyAddress;
			
				item.TradeID = varTradeID;
			
				item.ElectricID = varElectricID;
			
				item.PersonCardID = varPersonCardID;
			
				item.DepID = varDepID;
			
				item.Scores = varScores;
			
				item.Credit = varCredit;
			
				item.Status = varStatus;
			
				item.EnteringID = varEnteringID;
			
				item.VerifierID = varVerifierID;
			
				item.InTime = varInTime;
			
				item.Guid = varGuid;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn CompanyIDColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn CompanyNameColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn CompanyAddressColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn TradeIDColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn ElectricIDColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn PersonCardIDColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn DepIDColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn ScoresColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn CreditColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn StatusColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn EnteringIDColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        public static TableSchema.TableColumn VerifierIDColumn
        {
            get { return Schema.Columns[11]; }
        }
        
        
        
        public static TableSchema.TableColumn InTimeColumn
        {
            get { return Schema.Columns[12]; }
        }
        
        
        
        public static TableSchema.TableColumn GuidColumn
        {
            get { return Schema.Columns[13]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string CompanyID = @"CompanyID";
			 public static string CompanyName = @"CompanyName";
			 public static string CompanyAddress = @"CompanyAddress";
			 public static string TradeID = @"TradeID";
			 public static string ElectricID = @"ElectricID";
			 public static string PersonCardID = @"PersonCardID";
			 public static string DepID = @"DepID";
			 public static string Scores = @"Scores";
			 public static string Credit = @"Credit";
			 public static string Status = @"Status";
			 public static string EnteringID = @"EnteringID";
			 public static string VerifierID = @"VerifierID";
			 public static string InTime = @"inTime";
			 public static string Guid = @"Guid";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
